package com.bocai.eelly.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bocai.eelly.R;
import com.bocai.eelly.bean.NewsBean;
import com.bumptech.glide.Glide;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by admin on 2016/5/30.
 */
public class NewsAdp extends BaseAdapter {
    private Context context;
    private List<NewsBean.Data> news = new ArrayList<>();

    public NewsAdp(Context context, List<NewsBean.Data> news) {
        this.context = context;
        this.news = news;

    }

    @Override
    public int getCount() {
        return news.size();
    }

    @Override
    public Object getItem(int position) {
        return news.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.news_item, null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.tvNewsTitle.setText(news.get(position).getTitle());
        viewHolder.tvNewsContent.setText(news.get(position).getContent());
        Glide.with(context).load(news.get(position).getPhoto()).into(viewHolder.ivNewsPic);
        return convertView;
    }


    class ViewHolder {
        @Bind(R.id.iv_news_pic)
        ImageView ivNewsPic;
        @Bind(R.id.tv_news_title)
        TextView tvNewsTitle;
        @Bind(R.id.tv_news_content)
        TextView tvNewsContent;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
